package com.aim.Activity;

import com.aim.api.AIMCaseConstants;
import com.aim.util.Preferences;
import com.aim.util.WebServiceUtil;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Main extends Activity implements OnClickListener{
	Context mC;
	Button buttonEdit, buttonNew;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
    	
    	mC = this;        
    	WebServiceUtil.setContext(this);
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        buttonEdit = (Button) findViewById(R.id.buttonedit);
        buttonEdit.setOnClickListener(this);
        buttonNew = (Button) findViewById(R.id.buttonnew);
        buttonNew.setOnClickListener(this);
        
    }
    
    public void finish(){
    	mC = null;
    	buttonEdit = null;
    	buttonNew = null;
    	super.finish();
    }
    
    public void onClick(View v) {
    	if (v.equals(buttonEdit)) {
    		Intent mainMenu = new Intent(
					this,
					ImpoundList.class);
			
			startActivity(mainMenu);
    	}
    	else if (v.equals(buttonNew)){

    		Intent newImpound = new Intent(Main.this, ImpoundTab.class);
    		newImpound.putExtra("MODE", "new");
//    		forTab = 0;
//    		ImpoundTab.impoundState =0;
    		startActivity(newImpound);

    		
    	}
    }
    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {   
        menu.add(0,Menu.FIRST,0,"Log out");   
        menu.add(0,Menu.FIRST+1,1,"Settings"); 
        return super.onCreateOptionsMenu(menu);   
           
    }   
	@Override  
    public boolean onOptionsItemSelected(MenuItem item) {   
//        TextView tv = (TextView)findViewById(R.id.tv01);   
		super.onOptionsItemSelected(item); 
        switch(item.getItemId()){   
            case Menu.FIRST:{
            	SharedPreferences sp = mC.getSharedPreferences(Preferences.NAME, 0);
    			Editor sharedata = sp.edit();
    			
    			sharedata.putString(AIMCaseConstants.USERNAME,null);
    			sharedata.putString(AIMCaseConstants.PASSWORD,null);
    			sharedata.commit();
    			
    			Intent start = new Intent(this, Start.class);
    			startActivity(start);
    			this.finish();
            	break;   }
            
            case Menu.FIRST+1:{
            	Intent setting = new Intent (this, Settings.class);
            	startActivity(setting);
//            	deletePic();
            	break;   }
        }   
        return true;   
    } 

    
}